/*   1:    */ package com.atomikos.util;
/*   2:    */ 
/*   3:    */ import java.io.File;
/*   4:    */ import java.io.IOException;
/*   5:    */ import java.io.InputStream;
/*   6:    */ import java.io.OutputStream;
/*   7:    */ 
/*   8:    */ public class IOHelper
/*   9:    */ {
/*  10:    */   public static void copyBytes(InputStream in, OutputStream out)
/*  11:    */     throws IOException
/*  12:    */   {
/*  13: 54 */     byte[] buffer = new byte[1024];
/*  14: 55 */     int read = in.read(buffer);
/*  15: 56 */     while (read >= 0)
/*  16:    */     {
/*  17: 57 */       out.write(buffer, 0, read);
/*  18: 58 */       read = in.read(buffer);
/*  19:    */     }
/*  20:    */   }
/*  21:    */   
/*  22:    */   public static String getRelativePath(File fromFolder, File toFile)
/*  23:    */     throws IOException
/*  24:    */   {
/*  25: 75 */     String basePath = fromFolder.getAbsolutePath();
/*  26: 76 */     String filePath = toFile.getAbsolutePath();
/*  27: 77 */     if (!filePath.startsWith(basePath)) {
/*  28: 78 */       throw new IOException("The specified file is not within the folder.");
/*  29:    */     }
/*  30: 80 */     return filePath.substring(basePath.length() + 1);
/*  31:    */   }
/*  32:    */   
/*  33:    */   public static String getDifferencePath(File fromFolder, File toFile)
/*  34:    */     throws IOException
/*  35:    */   {
/*  36: 97 */     String commonParentPath = fromFolder.getParentFile().getAbsolutePath();
/*  37: 98 */     String filePath = toFile.getAbsolutePath();
/*  38: 99 */     if (!filePath.startsWith(commonParentPath)) {
/*  39:100 */       throw new IOException("The file should be contained in the parent directory of the stage folder.");
/*  40:    */     }
/*  41:103 */     return filePath.substring(commonParentPath.length() + 1);
/*  42:    */   }
/*  43:    */   
/*  44:    */   public static boolean createPathTo(File file, boolean isDirectory)
/*  45:    */     throws IOException
/*  46:    */   {
/*  47:119 */     boolean ret = false;
/*  48:120 */     File parent = file.getParentFile();
/*  49:121 */     if ((parent != null) && (!parent.exists())) {
/*  50:121 */       createPathTo(parent, true);
/*  51:    */     }
/*  52:122 */     if (isDirectory) {
/*  53:122 */       ret = file.mkdir();
/*  54:    */     } else {
/*  55:123 */       ret = file.createNewFile();
/*  56:    */     }
/*  57:127 */     return ret;
/*  58:    */   }
/*  59:    */   
/*  60:    */   public static boolean deleteContents(File folder)
/*  61:    */     throws IOException
/*  62:    */   {
/*  63:140 */     boolean deleted = true;
/*  64:141 */     if (!folder.isDirectory()) {
/*  65:142 */       throw new IOException("Not a directory");
/*  66:    */     }
/*  67:144 */     File[] contents = folder.listFiles();
/*  68:145 */     for (int i = 0; i < contents.length; i++) {
/*  69:146 */       if (contents[i].isDirectory())
/*  70:    */       {
/*  71:147 */         if (!deleteContents(contents[i])) {
/*  72:147 */           deleted = false;
/*  73:    */         }
/*  74:    */       }
/*  75:149 */       else if (!contents[i].delete()) {
/*  76:149 */         deleted = false;
/*  77:    */       }
/*  78:    */     }
/*  79:151 */     return deleted;
/*  80:    */   }
/*  81:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\atomikos-util\3.7.0\atomikos-util-3.7.0.jar
 * Qualified Name:     com.atomikos.util.IOHelper
 * JD-Core Version:    0.7.0.1
 */